<?php

namespace Lims\PaymentBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Utils\SecurityBundle\CustomClass\SecurityFunctions;
use Symfony\Component\HttpFoundation\RedirectResponse;


class ScheduleController extends Controller
{    
    public function getScheduleAction()
    {
        $em = $this->get('doctrine')->getManager();
        
        // get contract number
        if(!isset($_POST['creditId']))
        {
            $response = new Response(json_encode(array('status' => 'failed', 'msg' => 'Зээлийн график олдсонгүй!')));
            $response->headers->set('Content-Type', 'application/json');
            return $response;
        
            
        }
        // check scheduleId
        $creditId = (int) $_POST['creditId'];
        if($creditId == 0)
        {
            $response = new Response(json_encode(array('status' => 'failed', 'msg' => 'Зээлийн график олдсонгүй!')));
            $response->headers->set('Content-Type', 'application/json');
            return $response;
        }
        
        // find
        $creditSchedule = $em->getRepository('LimsMainBundle:CreditSchedule')->getScheduleForInquiryFull($creditId);        
        if(!$creditSchedule)
        {
            $result = array('status' => 'failed', 'data' => null);
        }else{
            $result = array('status' => 'success', 'data' => $creditSchedule);
        }
        
        $response = new Response(json_encode($result));
        $response->headers->set('Content-Type', 'application/json');
        return $response;
    }
    
}
